<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ include file="/jsp/common/commonTurnover.jsp"%>
<%@ include file="/jsp/common/commonCost.jsp"%>

<!doctype html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/common.js"/>"></script>


<script>
	var Address = [];//下拉数组

	var AddressCost = [];//下拉数组

	$.ajax({
		async : false,
		url : "<c:url value='/turnover/turnoverTypePullDown.do?space=0'/>",
		type : "post",
		data : {
			materType : 1
		},
		success : function(data) {
			Address = data;
			if (typeof (Address) == 'string') {
				Address = JSON.parse(Address);
			}
		}
	});

	$.ajax({
		async : false,
		url : "<c:url value='/cost/costTypePullDown.do?space=0'/>",
		type : "post",
		data : {
			materType : 1
		},
		success : function(data) {
			AddressCost = data;
			if (typeof (AddressCost) == 'string') {
				AddressCost = JSON.parse(AddressCost);
			}
		}
	});
	function initList(listDisplayEId) {
		$('#' + listDisplayEId)
				.datagrid(
						{
							url : "<c:url value='/turnover/listTurnoverSubForUpdate.do?custId=${FinancingVo.custId }&turnoverDate=${FinancingVo.date }'/>",
							nowrap : false,
							striped : true,
							collapsible : true,
							remoteSort : true,
							notSelectByRow : false,
							onLoadError : function() {
								$.messager.alert('错误', '获取数据失败，请与管理员联系！',
										'error');
							},
							columns : [ [ {
								field : 'turnoverSubId',
								title : 'id',
								width : 100,
								align : 'center',
								editor : {
									type : 'text',
									options : {
										required : true
									}
								},
								hidden : true
							}, {
								field : 'turnoverType',
								title : '营业种类',
								width : 100,
								align : 'center',
								formatter : formatTurnoverType

							}, {
								field : 'turnoverValue',
								title : '金额',
								width : 100,
								align : 'center',
								editor : {
									type : 'text',
									options : {
										required : true
									}
								}
							} ] ]

						});

	};
	function initList2(listDisplayEId) {
		$('#' + listDisplayEId)
				.datagrid(
						{
							url : "<c:url value='/cost/listCostSubForLook.do?custId=${FinancingVo.custId }&costDate=${FinancingVo.date }'/>",
							nowrap : false,
							striped : true,
							collapsible : true,
							remoteSort : true,
							notSelectByRow : false,
							onLoadError : function() {
								$.messager.alert('错误', '获取数据失败，请与管理员联系！',
										'error');
							},
							columns : [ [ {
								field : 'costSubId',
								title : 'id',
								width : 100,
								align : 'center',
								editor : {
									type : 'text',
									options : {
										required : true
									}
								},
								hidden : true
							}, {
								field : 'costType',
								title : '费用种类',
								width : 100,
								align : 'center',
								formatter : formatCostType
							}, {
								field : 'costValue',
								title : '金额',
								width : 100,
								align : 'center',
								editor : {
									type : 'text',
									options : {
										required : true
									}
								}
							}, {
								field : 'fileName',
								title : '图片链接',
								formatter : formatFilebox,
								width : 150,
								align : 'center'
							} ] ],
						});
	};
	$(document).ready(function() {
		document.getElementById("date").value = "${FinancingVo.date }";
		document.getElementById("date").value = "${FinancingVo.date }";

		initList('listDisplay');
		initList2('listDisplay2');

	});
	function formatFilebox(val, rowData, rowIndex) {
		return '<a href="#" onclick="downFile(\'' + rowData.costId + '\',\''
				+ rowData.costSubId + '\')">' + val + '</a>  '
	}
	function downFile(costId, costSubId) {
		/* var form = new FormData();
		form.append("fileName", fileName); // 可以增加表单数据
		var xhr = new XMLHttpRequest();
		xhr.open("post", '<c:url value='/financing/downFinancing.do'/>', true);
		xhr.send(form); */

		/* $.ajax({
		    async : false,
		    url : "<c:url value='/financing/downFinancing.do'/>",
		    type : "post",
		    ccess : function(data) {
		    }
		}); */
		window.location.href = "<c:url value='/financing/downFinancing.do'/>"
				+ "?costId=" + costId + "&costSubId=" + costSubId;
	}
</script>
</head>

<body>
	<table width="90%" align="center">
		<tr></tr>
		<tr>
			<td>

				<div style="height: auto; background: #fafafa; padding: 5px;"
					class="easyui-panel" title="添加营业额信息" iconCls="icon-save"
					collapsible="true" minimizable="false" maximizable="false"
					closable="false">

					<form id="AddFoodForm" name="AddFoodForm" method="post"
						enctype="multipart/form-data" action="userlist.txt"
						onsubmit="return searchDGData(this.id,'listDisplay');">
						<table cellpadding="5">
							<tr>
								<td colspan="3"><span style="color: red;">(注意!点击修改按钮时，请重新
										导入所有图片。如果没有备份图片信息请在查看页面点击链接下载)</span></td>
							</tr>
							<tr>
								<td>客户名:</td>
								<td><input class="easyui-validatebox" type="text"
									id="custName" name="custName" required="true"
									value="${FinancingVo.custName }" readOnly="true" /></td>
							</tr>
							<tr>
								<td>日期:</td>
								<td><input class="easyui-validatebox" type="text" id="date"
									name="date" value="${FinancingVo.date }" readOnly="true" /></td>
							</tr>
							<tr>
								<td><input type="hidden" id="custId" name="custId"
									value="${FinancingVo.custId }" /></td>
							</tr>
							<input name="turnoverId" type="hidden" id="turnoverId"
								value="${FinancingVo.turnoverId }" />
							<input name="costId" type="hidden" id="costId"
								value="${FinancingVo.costId }" />
							<input type="hidden" name="turnoverjson" id="turnoverjson" />
							<input type="hidden" name="costjson" id="costjson" />
						</table>
						<table cellpadding="5" width="500px">
							<tr>
								<td>
									<table id="listDisplay" title="营业种类列表" iconCls="icon-list"
										singleSelect="true" idField="turnoverSubId"
										loadMsg="请稍候......" pagination="false" rownumbers="true">
										<thead>
											<tr>
												<th field="turnoverSubId" width="80" sortable="true"
													editor="text">id</th>
												<th field="turnoverType" width="80" sortable="true"
													editor="combobox">营业种类</th>
												<th field="turnoverValue" width="80" sortable="true"
													editor="text">金额</th>
												<th field="button" width="40" align="center">删除</th>
											</tr>
										</thead>
									</table>
								</td>
							</tr>
						</table>
						<table cellpadding="5" width="500px">
							<tr>
								<td>
									<table id="listDisplay2" title="费用种类列表" iconCls="icon-list"
										singleSelect="true" idField="costSubId" loadMsg="请稍候......"
										pagination="false" rownumbers="true">
										<thead>
											<tr>
												<th field="costSubId" width="80" sortable="true"
													editor="text">id</th>
												<th field="costType" width="80" sortable="true"
													editor="combobox">费用种类</th>
												<th field="costValue" width="80" sortable="true"
													editor="text">金额</th>
												<th field="fileName" width="80" sortable="true">图片链接</th>
											</tr>
										</thead>
									</table>
								</td>
							</tr>
						</table>
					</form>
				</div>
			</td>
		</tr>
	</table>
</body>
</html>